<!doceventname html>
	<html>

	<head>
		<title>socket.io chat</title>
		<link rel="shortcut icon" href="#" />
	</head>

	<body>
		<script src="/socket.io/socket.io.js"></script>
		<script>

			var socket;

			function connect(nsp, username) {
				socket = io("/" + nsp);
				socket.on('connect', function () {
					// var data ={};
					// data.eventname="connected";
					// setWebViewString(data);
					socket.emit("login", username);
				});

				socket.on('disconnect', function (reason) {
					var data = {};
					data.eventname = "disconnected";
					data.reason = reason;
					setWebViewString(data);
				});

				socket.on("connected", function (data) {
					setWebViewString(data);
				});


				socket.on("matched", function (data) {
					setWebViewString(data);
				});

				socket.on("gotRoomMessage", function (data) {
					setWebViewString(data);
				});

				socket.on("gotPrivateMessage", function (data) {
					setWebViewString(data);
				});

				socket.on("gotPublicMessage", function (data) {
					setWebViewString(data);
				});

				socket.on("joinedRoom", function (data) {
					setWebViewString(data);
				});

				socket.on("otherJoinedRoom", function (data) {
					setWebViewString(data);
				});

				socket.on("leftRoom", function (data) {
					setWebViewString(data);
				});

				socket.on("otherLeftRoom", function (data) {
					setWebViewString(data);
				});

				socket.on("gotError", function (data) {
					setWebViewString(data);
				});
			}

			// function login(username){
			// 	socket.emit("login", username);
			// }

			function startMatch() {
				socket.emit("startMatch");
			}

			function cancelMatch() {
				socket.emit("cancelMatch");

			}

			function sendRoomMessage(roomname, message) {
				socket.emit("sendRoomMessage", roomname, message);
			}

			function sendPrivateMessage(receiver, message) {
				socket.emit("sendPrivateMessage", receiver, message);
			}

			function sendPublicMessage(message) {
				socket.emit("sendPublicMessage", message);
			}
			function leaveRoom(roomname) {
				socket.emit("leaveRoom", roomname);
			}

			function joinRoom(roomname) {
				socket.emit("joinRoom", roomname);
			}

			function disconnect() {
				socket.close();
			}

			function setMaxUser(maxuser) {
				socket.emit("setMaxUser", maxuser);

			}

			function setWebViewString(d) {
				if (window.AppInventor) {
					window.AppInventor.setWebViewString(JSON.stringify(d));
				}
				console.log(d);
			}

		</script>
	</body>

	</html>